﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_AirfareEdit : System.Web.UI.Page
{
    AirfareBusiness ab = new AirfareBusiness();
    private int id = Helper.getQuery("airfareID");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AirfareEntities ae = ab.getAirfare(id);
            bindDDLFight();
            bindDDLUser();
            bindDDLClass();
            bindDDLAirfareType();
            if (id > 0)
            {
                btnSubmit.Text = "Sửa";
                Label2.Text = id.ToString();
            }
        }
    }
    public void bindDDLFight()
   {
       FlightBusiness fb = new FlightBusiness();
       ddlFight.DataSource = fb.getAllFlight();
       ddlFight.DataTextField = "flightID";
       ddlFight.DataValueField = "flightID";
       ddlFight.DataBind();
   }
    public void bindDDLUser()
   {
       UserBusiness ub = new UserBusiness();
       ddlUser.DataSource = ub.getAllUser();
       ddlUser.DataTextField = "userName";
       ddlUser.DataValueField = "userID";
       ddlUser.DataBind();
   }
    public void bindDDLClass()
    {
        ClassBusiness cb = new ClassBusiness();
        ddlClass.DataSource = cb.getAllClass();
        ddlClass.DataTextField = "className";
        ddlClass.DataValueField = "classID";
        ddlClass.DataBind();

    }
    public void bindDDLAirfareType()
    {
        AirfareTypeBusiness atb = new AirfareTypeBusiness();
        ddlAirfareType.DataSource = atb.getAllAirfareType();
        ddlAirfareType.DataTextField = "airfareTypeName";
        ddlAirfareType.DataValueField = "airfareTypeID";
        ddlAirfareType.DataBind();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (btnSubmit.Text == "Sửa")
        {
            string[] values = { id.ToString(), ddlFight.SelectedValue, ddlUser.SelectedValue,ddlClass.SelectedValue,ddlAirfareType.SelectedValue,"0"};
            if (ab.Edit(values))
                Response.Redirect("Airfare.aspx");
            else
                Label1.Text = "Chưa sửa được";

        }
       
    }
}